﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CYTS.Aoyou.Framework.Log
{
    /// <summary>
    /// Web日志记录者
    /// </summary>
    public class WebLogger : Logger
    {
        private const string currentLoggerName = "CYTS.Aoyou.Framework.Log.WebLogger";

        /// <summary>
        /// 记录错误
        /// </summary>
        /// <param name="clientIP"></param>
        /// <param name="fromUrl"></param>
        /// <param name="referUrl"></param>
        /// <param name="uniqueID"></param>
        /// <param name="serverName"></param>
        /// <param name="message"></param>
        /// <param name="ex"></param>
        public static void LogError(string clientIP, string fromUrl, string referUrl, string uniqueID, string serverName, object message, Exception ex, string requestHost = "")
        {
            IWebLog logger = GetLogger<IWebLog>(currentLoggerName);
            if (logger.IsErrorEnabled)
            {
                logger.Error(clientIP, fromUrl, referUrl, uniqueID, serverName, requestHost, message, ex);
            }
        }

        public static void LogError(object message, Exception ex)
        {
            IWebLog logger = GetLogger<IWebLog>(currentLoggerName);
            if (logger.IsErrorEnabled)
            {
                logger.Error(message, ex);
            }
        }

        /// <summary>
        /// 记录消息
        /// </summary>
        /// <param name="clientIP"></param>
        /// <param name="fromUrl"></param>
        /// <param name="referUrl"></param>
        /// <param name="uniqueID"></param>
        /// <param name="serverName"></param>
        /// <param name="message"></param>
        public static void LogInfo(string clientIP, string fromUrl, string referUrl, string uniqueID, string serverName, object message, string requestHost = "")
        {
            IWebLog logger = GetLogger<IWebLog>(currentLoggerName);
            if (logger.IsInfoEnabled)
            {
                logger.Info(clientIP, fromUrl, referUrl, uniqueID, serverName, requestHost, message);
            }
        }

        public static void LogInfo(object message)
        {
            IWebLog logger = GetLogger<IWebLog>(currentLoggerName);
            if (logger.IsInfoEnabled)
            {
                logger.Info(message);
            }
        }
    }
}
